using System.Collections.Generic;
using System;

/*
    CssDom Library
    Copyright (C) 2007-2011  Ferenc Veres

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

namespace WPS.Modules.StyleLibrary
{
	/// <summary>
	/// Data class where StyleSheetManager can load a brief list of style names from WPS Stlye Library's wysiwyg.css file.
	/// </summary>
	public class StyleNameList
	{
		/// <summary>Font styling class names</summary>
		public List<string> Fonts
		{
			get { return m_Fonts; }
			set { m_Fonts = value; }
		}
		private List<string> m_Fonts = new List<string>();

		/// <summary>Image styling class names</summary>
		public List<string> Images
		{
			get { return m_Images; }
			set { m_Images = value; }
		}
		private List<string> m_Images = new List<string>();
		
		/// <summary>Table styling class names</summary>
		public List<string> Tables
		{
			get { return m_Tables; }
			set { m_Tables = value; }
		}
		private List<string> m_Tables = new List<string>();

		/// <summary>Text box styling class names</summary>
		public List<string> TextBoxes
		{
			get { return m_TextBoxes; }
			set { m_TextBoxes = value; }
		}
		private List<string> m_TextBoxes = new List<string>();

		/// <summary>
		/// Create empty style names list data object, for loading style names from WPS Style Library's "wysiwyg.css" file.
		/// </summary>
		public StyleNameList()
		{
		}

		/// <summary>
		/// Executes a case insensitive search for the given class name in all lists.
		/// Returns the list that contains the class or null if none.
		/// </summary>
		/// <remarks>
		/// Normally one class may be in only one list, but if there are duplicates,
		/// this function simply returns the first match it finds.
		/// </remarks>
		/// <returns>The list that cotains the class or null.</returns>
		public List<string> FindClass(string style)
		{
			if(Contains(this.Fonts, style))
			{
				return this.Fonts;
			}
			else if(Contains(this.Images, style))
			{
				return this.Images;
			}
			else if(Contains(this.Tables, style))
			{
				return this.Tables;
			}
			else if(Contains(this.TextBoxes, style))
			{
				return this.TextBoxes;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// Checks if the given lists contains the given style name, case insensitve.
		/// </summary>
		/// <param name="list">In which list to find.</param>
		/// <param name="style">Which style class name to find.</param>
		/// <returns>True if the case insensitve match was successful to a name.</returns>
		private bool Contains(List<string> list, string style)
		{
			return (list.Find(delegate(string s)
			{
				return (String.Compare(s, style, true) == 0);
			}) != null);
		}
	}
}